#include "tcp_server_thread.hpp"
#include "daemon.hpp"
using namespace ns_server;

static void usage(string proc){
    cout << "Usage:\n\t" << proc << "port\n"
         << endl;
}

string echo(const string& msg){
    return msg;
}

// ./tcp_server port
int main(int argc, char* argv[]){

    cout << " ↓ server ↓ " << endl;

    //检查argv的字符串数量是否为2
    if(argc != 2){
        usage(argv[0]);
        exit(USAGE_ERR);
        cerr << "argc != 2" << endl; 
    }

    uint16_t port = atoi(argv[1]);

    unique_ptr<tcp_server> tsvr(new tcp_server(echo,port));

    tsvr->init();

    //让服务器守护进程化
    Daemon();

    tsvr->start();

    return 0;
}